package config

import "fmt"

// ValidateConfig 验证配置的有效性
func ValidateConfig(config Config) error {
	if config.StaticFolder == "" {
		return fmt.Errorf("static_folder cannot be empty")
	}
	if config.NotFoundPage == "" {
		return fmt.Errorf("not_found_page cannot be empty")
	}
	if config.Host == "" {
		return fmt.Errorf("host cannot be empty")
	}
	if config.Port == "" {
		return fmt.Errorf("port cannot be empty")
	}
	// 如果启用了开发者拦截器，验证用户名和密码
	if config.DevInterceptorEnabled {
		if config.DevUsername == "" {
			return fmt.Errorf("dev_username cannot be empty when dev_interceptor_enabled is true")
		}
		if config.DevPassword == "" {
			return fmt.Errorf("dev_password cannot be empty when dev_interceptor_enabled is true")
		}
	}
	return nil
}

// IsHostLocal 检查主机地址是否为本地地址
func IsHostLocal(host string) bool {
	return host == "127.0.0.1" || host == "localhost"
}

// IsHostAccessible 检查主机地址是否允许外部访问
func IsHostAccessible(host string) bool {
	return host == "0.0.0.0"
}